﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using NaireSystem.Datas;
using NaireSystem.DBEntity;
using TYBase;

namespace NaireSystem.Api
{
    public class DictTypeApi
    {
        public static R<List<Tbl_DictType>> GetList(Tbl_DictType queryDto)
        {
            try
            {
                
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/dictType/getList?{queryDto.AsQueryData()}").SetGet().Excute(out string data))
                {
                    return R<List<Tbl_DictType>>.Fail(data);
                }
                return data.AsModel<R<List<Tbl_DictType>>>();
            }
            catch (Exception ex)
            {
                return R<List<Tbl_DictType>>.Fail("获取字典失败!", ex);
            }
        }
        public static R<bool> AddItem(Tbl_DictType queryDto)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/dictType/addItem")
                    .SetData(queryDto.JsonAsString())
                    .SetPost().Excute(out string data))
                {
                    return R<bool>.Fail(data);
                }
                return data.AsModel<R<bool>>();
            }
            catch (Exception ex)
            {
                return R<bool>.Fail("添加字典失败!!", ex);
            }
        }
        public static R<bool> DeleteItem(int dict_id)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/dictType/addItem?dict_type_id={dict_id}")
                    .SetPost().
                    Excute(out string data))
                {
                    return R<bool>.Fail(data);
                }
                return data.AsModel<R<bool>>();
            }
            catch (Exception ex)
            {
                return R<bool>.Fail("删除字典失败!!", ex);
            }
        }

    }
}
